/*
 * Powered By [leyvi]
 * Since 2014 - 2015
 */


var collect = {};
var common = require('../../utils/commonUtils');
//db转换成model
collect.dbConvertModel = function(db){
	var collect = {}; 
	if(common.isNotBlank(db.id)) collect.id = db.id;	
	if(common.isNotBlank(db.article_id)) collect.articleId = db.article_id;	
	if(common.isNotBlank(db.member_id)) collect.memberId = db.member_id;	
	if(common.isNotBlank(db.status)) collect.status = db.status;	
	if(common.isNotBlank(db.create_time)){
		collect.createTime = db.create_time;
		collect.createTimeStr = db.create_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.update_time)){
		collect.updateTime = db.update_time;
		collect.updateTimeStr = db.update_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.bak1)) collect.bak1 = db.bak1;	
	if(common.isNotBlank(db.bak2)) collect.bak2 = db.bak2;	
	if(common.isNotBlank(db.bak3)) collect.bak3 = db.bak3;	
	if(typeof db.bak4 != "undefined") collect.bak4 = db.bak4;
	if(typeof db.bak5 != "undefined") collect.bak5 = db.bak5;
	return collect;
};

//model转换成db
collect.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.id = obj.id;
	if(common.isNotBlank(obj.articleId)) db.article_id = obj.articleId;
	if(common.isNotBlank(obj.memberId)) db.member_id = obj.memberId;
	if(common.isNotBlank(obj.status)) db.status = obj.status;
	if(common.isNotBlank(obj.createTime)) db.create_time = obj.createTime;
	if(common.isNotBlank(obj.updateTime)) db.update_time = obj.updateTime;
	if(common.isNotBlank(obj.bak1)) db.bak1 = obj.bak1;
	if(common.isNotBlank(obj.bak2)) db.bak2 = obj.bak2;
	if(common.isNotBlank(obj.bak3)) db.bak3 = obj.bak3;
	if(typeof obj.bak4 != "undefined") db.bak4 = obj.bak4;
	if(typeof obj.bak5 != "undefined") db.bak5 = obj.bak5;
	return db;
};

collect.initPostReq = function(req){
	var collect = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (collect.id = req.body.id) : (collect.id = req.body.id.trim());
	}
	if(req.body.articleId != undefined){
		(typeof req.body.articleId != 'string') ? (collect.articleId = req.body.articleId) : (collect.articleId = req.body.articleId.trim());
	}
	if(req.body.memberId != undefined){
		(typeof req.body.memberId != 'string') ? (collect.memberId = req.body.memberId) : (collect.memberId = req.body.memberId.trim());
	}
	if(req.body.status != undefined){
		(typeof req.body.status != 'string') ? (collect.status = req.body.status) : (collect.status = req.body.status.trim());
	}
	if(req.body.createTime != undefined){
		(typeof req.body.createTime != 'string') ? (collect.createTime = req.body.createTime) : (collect.createTime = req.body.createTime.trim());
	}
	if(req.body.updateTime != undefined){
		(typeof req.body.updateTime != 'string') ? (collect.updateTime = req.body.updateTime) : (collect.updateTime = req.body.updateTime.trim());
	}
	if(req.body.bak1 != undefined){
		(typeof req.body.bak1 != 'string') ? (collect.bak1 = req.body.bak1) : (collect.bak1 = req.body.bak1.trim());
	}
	if(req.body.bak2 != undefined){
		(typeof req.body.bak2 != 'string') ? (collect.bak2 = req.body.bak2) : (collect.bak2 = req.body.bak2.trim());
	}
	if(req.body.bak3 != undefined){
		(typeof req.body.bak3 != 'string') ? (collect.bak3 = req.body.bak3) : (collect.bak3 = req.body.bak3.trim());
	}
	if(req.body.bak4 != undefined){
		(typeof req.body.bak4 != 'string') ? (collect.bak4 = req.body.bak4) : (collect.bak4 = req.body.bak4.trim());
	}
	if(req.body.bak5 != undefined){
		(typeof req.body.bak5 != 'string') ? (collect.bak5 = req.body.bak5) : (collect.bak5 = req.body.bak5.trim());
	}
	return collect;
};

collect.initGetReq = function(req){
	var collect = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (collect.id = req.query.id) : (collect.id = req.query.id.trim());
	}
	if(req.query.articleId != undefined){	
		(typeof req.query.articleId != 'string') ? (collect.articleId = req.query.articleId) : (collect.articleId = req.query.articleId.trim());
	}
	if(req.query.memberId != undefined){	
		(typeof req.query.memberId != 'string') ? (collect.memberId = req.query.memberId) : (collect.memberId = req.query.memberId.trim());
	}
	if(req.query.status != undefined){	
		(typeof req.query.status != 'string') ? (collect.status = req.query.status) : (collect.status = req.query.status.trim());
	}
	if(req.query.createTime != undefined){	
		(typeof req.query.createTime != 'string') ? (collect.createTime = req.query.createTime) : (collect.createTime = req.query.createTime.trim());
	}
	if(req.query.updateTime != undefined){	
		(typeof req.query.updateTime != 'string') ? (collect.updateTime = req.query.updateTime) : (collect.updateTime = req.query.updateTime.trim());
	}
	if(req.query.bak1 != undefined){	
		(typeof req.query.bak1 != 'string') ? (collect.bak1 = req.query.bak1) : (collect.bak1 = req.query.bak1.trim());
	}
	if(req.query.bak2 != undefined){	
		(typeof req.query.bak2 != 'string') ? (collect.bak2 = req.query.bak2) : (collect.bak2 = req.query.bak2.trim());
	}
	if(req.query.bak3 != undefined){	
		(typeof req.query.bak3 != 'string') ? (collect.bak3 = req.query.bak3) : (collect.bak3 = req.query.bak3.trim());
	}
	if(req.query.bak4 != undefined){	
		(typeof req.query.bak4 != 'string') ? (collect.bak4 = req.query.bak4) : (collect.bak4 = req.query.bak4.trim());
	}
	if(req.query.bak5 != undefined){	
		(typeof req.query.bak5 != 'string') ? (collect.bak5 = req.query.bak5) : (collect.bak5 = req.query.bak5.trim());
	}
	return collect;
};


module.exports = collect;
